package com.bl.weilan.manager.controller.institutionteam;

import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.manager.controller.BaseController;
import com.bl.weilan.service.biz.institution.InstitutionService;
import com.bl.weilan.service.biz.institutionteam.InstitutionTeamService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.institution.InstitutionAddVo;
import com.bl.weilan.service.vo.institution.InstitutionModVo;
import com.bl.weilan.service.vo.institutionteam.InstitutionTeamAddVo;
import com.bl.weilan.service.vo.institutionteam.InstitutionTeamModVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/manager/institutionteam"})
@Api(value = "团队相关", description = "团队相关manager")
public class InstitutionTeamController extends BaseController {
    @Autowired
    InstitutionTeamService institutionTeamService;

    @ApiOperation(value = "删除一条团队信息", notes = "删除一条团队信息 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {
        institutionTeamService.del(body);
        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "编辑团队信息", notes = "编辑团队信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/modify"})
    public ApiResponseBody modify(
            @Valid @RequestBody InstitutionTeamModVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }
        institutionTeamService.modify(body);
        return ApiResponseBody.createSuccessBody(null);
    }


    @ApiOperation(value = "新增团队信息", notes = "新增团队信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add"})
    public ApiResponseBody add(
            @Valid @RequestBody InstitutionTeamAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }
        institutionTeamService.add(body);
        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除批量", notes = "删除批量 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_list"})
    public ApiResponseBody delList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        institutionTeamService.delList(body);

        return ApiResponseBody.createSuccessBody(null);
    }

}
